package cn.com.xf.utils;

import java.text.Normalizer.Form;
import java.util.ArrayList;
import java.util.List;

import cn.com.xf.domain.Tbchinaarea;

public class CheckChinaArea {
	/**
	 * 核对区
	 */
	public static String checkArea(String inArea,List<Tbchinaarea> listCAA) {
		String outArea="";
		int a = 0;
		if(inArea.equals("")) {
			return inArea;
		}
		for (int i = 0; i < listCAA.size(); i++) {
			String area = listCAA.get(i).getArea();
			String areaSub = area.substring(0,2);
			String inAreaSub = inArea.substring(0, 2);
			if(areaSub.equals(inAreaSub)) {
				a++;
				outArea = area;
			}else {
				outArea = inArea;
			}
		}
		if(a <= 1) {
			return outArea;
		}else if(a > 1) {
			for (int i = 0; i < listCAA.size(); i++) {
				String area = listCAA.get(i).getArea();
				String areaSub = area.substring(0,3);
				String inAreaSub = inArea.substring(0, 3);
				if(areaSub.equals(inAreaSub)) {					
					outArea = area;
					return outArea;
				}
			}
		}
		return outArea;
		
	}
	
	/**
	 * 核对市，对比字符串，选取字符相同最多的字符串
	 * @param 输入市
	 * @param listPAC 省市数据
	 * @return
	 */
	public static String checkCity(String inCity,List<Tbchinaarea> listPAC){
		int c = 0;
		String outcity = "";
		if(inCity.equals("")) {
			return inCity;
		}
		for (int i = 0; i < listPAC.size(); i++) {
			String city = listPAC.get(i).getCity();
			String citySub = city.substring(0,2);
			String inCitySub = inCity.substring(0,2);
			if(citySub.equals(inCitySub)) {
				c++;
				outcity = city;
			}else {
				outcity = inCity;
			}
		}
		if(c <= 1) {
			return outcity;
		}else if(c >1){
			for (int i = 0; i < listPAC.size(); i++) {
				String city = listPAC.get(i).getCity();
				String citySub = city.substring(0,3);
				String inCitySub = inCity.substring(0,3);
				if(citySub.equals(inCitySub)) {
					outcity = city;
					return outcity;
				}
			}
		}
		return outcity;		
	}
	
	/**
	 * 核对省
	 * @param prov
	 * @return 输出指定省
	 */
	public static String checkProv(String prov){
		String[] provArr ={"北京市","天津市","山东省","山西省","河南省","河北省","内蒙古自治区","江苏省",
				"浙江省","黑龙江省","吉林省","辽宁省","上海市","湖南省","湖北省","广东省","广西壮族自治区",
				"海南省","新疆维吾尔自治区","重庆市","四川省","云南省","甘肃省","宁夏回族自治区","陕西省",
				"西藏自治区","香港特别行政区","澳门特别行政区","台湾省","贵州省","福建省","安徽省",
				"青海省","江西省"};
		if(prov.indexOf("兵团") >= 0){
			return prov;
		}else{
			for (int i = 0; i < provArr.length; i++) {
				String provStr = provArr[i].substring(0,2);
				if(provStr.equals(prov.substring(0,2))) {
					return provArr[i];
				}
			}
		}		
		return prov;		
	}		
	
}
